import request from '@/sheep/request';
import { baseUrl } from '@/sheep/config';

export default {
  // 系统初始化
  init: (templateId) =>
    request({
      url: 'index/init',
      params: {
        templateId,
      },
      custom: {
        showError: false,
        showLoading: false,
        showSuccess: false,
        successMsg: '',
        errorMsg: '',
      },
      
    }),
    // 获取所有组织结构
    getDepartment: (params) =>
      request({
        url: 'api/department/get_department',
        method: 'GET',
        params,
        custom: {
          showSuccess: false,
          successMsg: '',
          showError: true,
          errorMsg: '',
          showLoading: false,
          loadingMsg: '加载中',
          auth: true,
        },
      }),
       // 获取项目负责人所有部门
       getUserRespomsibleList: (params) =>
        request({
          url: 'api/department/get_user_responsible_list',
          method: 'GET',
          params,
          custom: {
            showSuccess: false,
            successMsg: '',
            showError: true,
            errorMsg: '',
            showLoading: false,
            loadingMsg: '加载中',
            auth: true,
          },
        }),
        
      // 选择城市 接收返回值id
      get_city: (params) =>
      request({
        url: 'api/dispatch/get_city',
        method: 'POST',
        params,
        custom: {
          showSuccess: false,
          successMsg: '',
          showError: true,
          errorMsg: '',
          showLoading: false,
          loadingMsg: '加载中',
          auth: true,
        },
      }),
      // 邀请信息
      Post_dispatch_invite_info: (params) =>
        request({
          url: 'api/dispatch_invite_info/add',
          method: 'POST',
          params,
          custom: {
            showSuccess: false,
            successMsg: '',
            showError: false,
            errorMsg: '',
            showLoading: false,
            loadingMsg: '加载中',
            auth: true,
          },
        }),
      //邀请同事
      Post_entryinfo_invite_info: (params) =>
        request({
          url: 'api/entryinfo_invite_info/add',
          method: 'POST',
          params,
          custom: {
            showSuccess: false,
            successMsg: '',
            showError: true,
            errorMsg: '',
            showLoading: false,
            loadingMsg: '加载中',
            auth: true,
          },
        }),
             //邀请外包
      Post_enpiboly_invite_add: (params) =>
        request({
          url: 'api/epiboly_Invite_Info/add',
          method: 'POST',
          params,
          custom: {
            showSuccess: false,
            successMsg: '',
            showError: true,
            errorMsg: '',
            showLoading: false,
            loadingMsg: '加载中',
            auth: true,
          },
        }),
  // 同步客户端页面到后端
  pageSync: (pages) =>
    request({
      url: 'index/pageSync',
      method: 'POST',
      data: {
        pages,
      },
      custom: {
        showError: false,
        showLoading: false,
      },
    }),
  // 发送短信
  sendSms: (data) =>
    request({
      url: 'index/send',
      method: 'POST',
      data,
      custom: {
        showSuccess: true,
        loadingMsg: '发送中',
      },
    }),

  // 自定义页面
  page: (id) =>
    request({
      url: 'index/page',
      method: 'GET',
      params: {
        id: id,
      },
    }),

  //小程序直播
  mplive: {
    getMpLink: () =>
      request({
        url: 'app.mplive/getMpLink',
        method: 'GET',
      }),
    getRoomList: (ids) =>
      request({
        url: 'app.mplive/getRoomList',
        method: 'GET',
        params: {
          ids: ids.join(','),
        }
      }),
  },

  //上传
  upload: (file, group = 'ugc', callback) => {
    const token = uni.getStorageSync('token');
    uni.showLoading({
      title: '上传中',
    });
    return new Promise((resolve, reject) => {
      uni.uploadFile({
        url: baseUrl + '/api/common/upload',
        filePath: file,
        name: 'file',
        formData: {
          group,
        },
        header: {
          Accept: 'text/json',
          // Authorization: token,
          token: token
        },
        success: (uploadFileRes) => {
          let result = JSON.parse(uploadFileRes.data);
          if (result.code === 0) {
            uni.showToast({
              icon: 'none',
              title: result.msg,
            });
          } else {
            return resolve(result.data);
          }
        },
        fail: (error) => {
          return resolve(false);
        },
        complete: () => {
          uni.hideLoading();
        },
      });
    });
  },
};
